import request from './index'

export interface ExportParams {
  category_id?: number
}

export interface ImportOptions {
  skip_duplicates?: boolean
  update_existing?: boolean
}

export interface BackupInfo {
  filename: string
  size: number
  created_at: string
}

/**
 * 导出为JSON
 */
export function exportAccountsJson(params?: ExportParams) {
  return request.get('/api/import/export-json', { params })
}

/**
 * 导出为CSV
 */
export function exportAccountsCsv(params?: ExportParams) {
  return request.get('/api/import/export-csv', { params })
}

/**
 * 导入JSON数据
 */
export function importAccountsJson(data: any, options?: ImportOptions) {
  return request.post('/api/import/import-json', {
    data,
    ...options
  })
}

/**
 * 导入CSV数据
 */
export function importAccountsCsv(data: any[][], options?: ImportOptions) {
  return request.post('/api/import/import-csv', {
    data,
    ...options
  })
}

/**
 * 创建备份
 */
export function createBackup() {
  return request.post('/api/import/create-backup')
}

/**
 * 列出备份
 */
export function listBackups(): Promise<BackupInfo[]> {
  return request.get('/api/import/list-backups')
}

/**
 * 恢复备份
 */
export function restoreBackup(filename: string) {
  return request.post('/api/import/restore-backup', { filename })
}

/**
 * 删除备份
 */
export function deleteBackup(filename: string) {
  return request.delete('/api/import/delete-backup', { data: { filename } })
}
